/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://dylab.googlecode.com

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

#ifndef __dylab_Tetrahedron_h__
#define __dylab_Tetrahedron_h__

//===========================================================================================
#include <dylab/simobject/tetravol/Triangle.h>
#include <dylab/utils/geometry/TetrahedronGeometry.h>


//===========================================================================================
namespace dylab {

    /** This class represents a tetrahedron
	*/
    class DYLAB_EXPORT Tetrahedron
    {
    public:
        typedef uint32_t id_t;

    protected:
        id_t mId;
        MassPoint * mMassPoints[TetrahedronGeometry::V_COUNT];

    public:
        Tetrahedron();
        Tetrahedron(id_t _id, MassPoint * _mp0, MassPoint * _mp1, MassPoint * _mp2, MassPoint * _mp3);
        Tetrahedron(id_t _id, MassPoint * (&_mp)[TetrahedronGeometry::V_COUNT]);
        virtual ~Tetrahedron();

        id_t getId() const
                { return mId; }

        MassPoint * getMassPoint(TetrahedronGeometry::vertexidx_t _vertexIdx)
                { DYLAB_ASSERT(mMassPoints[_vertexIdx] != NULL);
                    return mMassPoints[_vertexIdx]; }
        const MassPoint * getMassPoint(TetrahedronGeometry::vertexidx_t _vertexIdx) const
                { DYLAB_ASSERT(mMassPoints[_vertexIdx] != NULL);
                    return mMassPoints[_vertexIdx]; }

        TetrahedronGeometry getGeometry() const
                { return TetrahedronGeometry(getMassPoint(TetrahedronGeometry::V_0)->currState().position, 
					getMassPoint(TetrahedronGeometry::V_1)->currState().position, 
					getMassPoint(TetrahedronGeometry::V_2)->currState().position, 
					getMassPoint(TetrahedronGeometry::V_3)->currState().position); }

        /// Tests, if mass point id is part of the tetrahedron.
        bool containsMassPointId(MassPoint::id_t _mpId);

        virtual Edge::id_t		getEdgeID(TetrahedronGeometry::edgeidx_t _edgeIdx) const;
        virtual Triangle::id_t	getTriangleID(TetrahedronGeometry::faceidx_t _faceIdx) const;
    };
    //-----------------------------------------------------------------------------

	//===========================================================================================
    class DYLAB_EXPORT TetrahedronContainer
        : public HashObjContainer<Tetrahedron::id_t, Tetrahedron>
    {
    public:
        TetrahedronContainer(bool _objectOwner)
            : HashObjContainer<Tetrahedron::id_t, Tetrahedron>(_objectOwner)
                { }
    };
    //-----------------------------------------------------------------------------
}
//===========================================================================================
#endif // __dylab_Tetrahedron_h__
